# get.todorov.sendata.r
#
# Script to call in Todorov's Senate data
# from SPSS files and clean to be mergeable
# with Atkinson Enos Hill data.

library(foreign)

# Call in and configure Todorov data.
tod.04 <- read.spss("todorovdata/Senate_2004.sav",
        use.value.labels=FALSE,to.data.frame=TRUE)
tod.04 <- tod.04[,c("CASE_LBL","COMP_D")]
tod.04$state <- substr(as.character(tod.04$CASE_LBL),1,2)
tod.04[as.character(tod.04$CASE_LBL)=="ALAB_D  ","state"] <- "AL"
tod.04[as.character(tod.04$CASE_LBL)=="ALAS_D  ","state"] <- "AK"
tod.04[as.character(tod.04$CASE_LBL)=="ARKA_D  ","state"] <- "AR"
tod.04[as.character(tod.04$CASE_LBL)=="CONN_D  ","state"] <- "CT"
tod.04[as.character(tod.04$CASE_LBL)=="IOWA_D  ","state"] <- "IA"
tod.04[as.character(tod.04$CASE_LBL)=="KZ_D    ","state"] <- "KS"
tod.04[as.character(tod.04$CASE_LBL)=="NEV_D   ","state"] <- "NV"
tod.04$year <- rep(2004,nrow(tod.04))
tod.04 <- tod.04[,c("COMP_D","state","year")]

tod.02 <- read.spss("todorovdata/Senate_2002.sav",
        use.value.labels=FALSE,to.data.frame=TRUE)
tod.02$COMP_D <- ifelse(tod.02$PARTY_W=="D ",tod.02$COM_N156,1-tod.02$COM_N156)
tod.02 <- tod.02[,c("COMP_D","CASE_LBL")]
names(tod.02) <- c("COMP_D","state")
tod.02$state <- substr(tod.02$state,1,2)
tod.02$year <- rep(2002,nrow(tod.02))

tod.00 <- read.spss("todorovdata/Senate_2000.sav",
        use.value.labels=FALSE,to.data.frame=TRUE)
tod.00$COMP_D <- ifelse(tod.00$PARTY_W=="D ",tod.00$COM_N156,1-tod.00$COM_N156)
tod.00 <- tod.00[,c("COMP_D","CASE_LBL")]
names(tod.00) <- c("COMP_D","state")
tod.00$state <- substr(tod.00$state,1,2)
tod.00$year <- rep(2000,nrow(tod.00))

tod <- rbind(tod.04,tod.02,tod.00)
rm( tod.04,tod.02,tod.00 )
